package com.weng.cloud.service8881.jaxrs.service;

import com.weng.cloud.commons.base.JsonUtil;
import com.weng.cloud.service8881.jaxrs.entity.Song;
import com.weng.cloud.service8881.jaxrs.entity.TestJaxRsEntity;

import javax.ws.rs.*;

/**
 * @Author: weng
 * @Date: 2022/5/1
 * @Description: com.weng.cloud.service8881.jaxrs.service
 */
@Path("/cxf")
public class TestCXFService {

    @Path("/simpleQuery")
    @GET
    public String simpleQuery(){
        return "this is a simple query";
    }

    @Path("/simplePost/{arg}")
    //不能同时加上@GET、@POST、@PUT...
    @POST
    //@Consumes({MediaType.APPLICATION_JSON})
    //该方式无法实现
    //public String simplePost(Song song){
    public String simplePost(
            //请求体参数(难受的是无法被beanParam解构，只能放在bean外面)
       String body,
 /*            , @Context HttpServletRequest req
            , @HeaderParam("h") String h
            , @QueryParam("qp1") String qp1
            , @DefaultValue("fault") @QueryParam("qp2") String qp2
            , @PathParam("arg") String arg*/
        @BeanParam TestJaxRsEntity entity
            )
    {
//        Song song = JsonUtil.toObject(body, Song.class);
        Song song = JsonUtil.toObject(entity.getBody(), Song.class);
        return "this is a simple post --> "+song.getName();
    }
}
